/*
 * JP_ModicarCuentaContable.java
 *
 * Created on 25 de noviembre de 2008, 08:54 AM
 */

package Enlaces;
import utiles.*;
import java.util.*;
import java.awt.*;


/**
 *
 * @author  Frank
 */
public class JP_ModicarCuentaContable extends Utiles_PanelModelo {

    /** Creates new form JP_ModicarCuentaContable */
    public JP_ModicarCuentaContable( int op ) {
        inicializaComponentes( op );
        this.operacion = op;
    }
    
    
    public void inicializaComponentes( int op ){
        initComponents();
        
        //Inicializa barra de operaciones
        ArrayList alBotones = new ArrayList( 1 );        
        
        alBotones.add( new Integer( Utiles_PanelBotonesMantenimiento.BOTON_GUARDAR ) );        
        alBotones.add( new Integer( Utiles_PanelBotonesMantenimiento.BOTON_LIMPIAR ) );        
        alBotones.add( new Integer( Utiles_PanelBotonesMantenimiento.BOTON_CERRAR ) );        
        upbm = new Utiles_PanelBotonesMantenimiento( this, alBotones );                
        jpOperaciones.setLayout( new BorderLayout() );
        jpOperaciones.add( upbm, BorderLayout.CENTER );
        
        if( op == OPERACION_MODIFICA ){
            this.jtfCtaCont.setEnabled( false );            
        }
    }
    
    public void nuevo(){
        
    }
    
    public void guardar(){
                
        idCtaCont = this.jtfCtaCont.getText();
        descCtaCont = this.jtfDescCtaCont.getText();
        tipoCtaCont = this.jcbTipoCtaContDH.getSelectedItem().toString();
        flagPpto = this.jchkFlagPpto.isSelected();          
        if( this.operacion == OPERACION_NUEVO ){                                  
            try{
                this.getClienteEnlaces().getObjeto().ingresaCuentaContable( idCtaCont , descCtaCont, tipoCtaCont, flagPpto, this.getIDUser() );            
            }catch( java.sql.SQLException er ){
                er.printStackTrace();                
            }catch( java.rmi.RemoteException er ){
                er.printStackTrace();
            }
        }else if( this.operacion == OPERACION_MODIFICA ){
            try{
                this.getClienteEnlaces().getObjeto().modificaCuentaContable( idCtaCont , descCtaCont, tipoCtaCont, flagPpto, this.getIDUser() );            
            }catch( java.sql.SQLException er ){
                er.printStackTrace();
            }catch( java.rmi.RemoteException er ){
                er.printStackTrace();
            }            
        }       
        this.upbm.jbGuardar.setEnabled( false );
        System.out.println( "Se ejecuta antes" );
        ( ( JP_AdministrarCuentasContables ) this.getRefDep() ).consultarCuentasContables();
        System.out.println( "Se ejecuta despues" );
    }
    
    public void modificar(){
        
    }
    
    public void eliminar(){
        
    }
        
    public void limpiar(){
        this.jtfDescCtaCont.setText( "" );
        this.jchkFlagPpto.setSelected( false );                
        if( this.operacion == OPERACION_NUEVO ){
            this.jtfCtaCont.setText( "" );           
        }
    }
    
    public void detalles(){
        
    }
    
    public void imprimir(){
        
    }
    
    public void cerrar(){              
        this.cerrarPadre();        
    }
    
    public void setIdCtaCont( String idCtaCont ){
        this.idCtaCont = idCtaCont;        
    }
    
    public void setDescCtaCont( String descCtaCont ){
        this.descCtaCont = descCtaCont;        
    }
    
    public void setTipoCtaDH( String tipoCtaCont ){
        this.tipoCtaCont = tipoCtaCont;        
    }
    
    public void setFlagPpto( boolean flagPpto ){
        this.flagPpto = flagPpto;        
    }
    
    
    public void inicializaDatos(){
        this.jtfCtaCont.setText( this.idCtaCont );
        this.jtfDescCtaCont.setText( this.descCtaCont );
        this.jcbTipoCtaContDH.setSelectedItem( this.tipoCtaCont );
        this.jchkFlagPpto.setSelected( this.flagPpto );                
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpOperaciones = new javax.swing.JPanel();
        jpDatos = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtfDescCtaCont = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jlCta = new javax.swing.JLabel();
        jtfCtaCont = new javax.swing.JTextField();
        jchkFlagPpto = new javax.swing.JCheckBox();
        jcbTipoCtaContDH = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();

        jpOperaciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Operaciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        javax.swing.GroupLayout jpOperacionesLayout = new javax.swing.GroupLayout(jpOperaciones);
        jpOperaciones.setLayout(jpOperacionesLayout);
        jpOperacionesLayout.setHorizontalGroup(
            jpOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 355, Short.MAX_VALUE)
        );
        jpOperacionesLayout.setVerticalGroup(
            jpOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 34, Short.MAX_VALUE)
        );

        jpDatos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos de Cuenta Corriente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("Desc. Cuenta Contable:");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("Flag Presupuesto:");

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("Tipo Cuenta Contable:");

        jtfDescCtaCont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescCtaContActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("Id. Cuenta Contable:");

        jlCta.setFont(new java.awt.Font("Arial", 1, 12));
        jlCta.setText("  ");

        jtfCtaCont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCtaContActionPerformed(evt);
            }
        });

        jcbTipoCtaContDH.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "D", "H" }));

        jLabel7.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel7.setText("(Debe/Haber)");

        javax.swing.GroupLayout jpDatosLayout = new javax.swing.GroupLayout(jpDatos);
        jpDatos.setLayout(jpDatosLayout);
        jpDatosLayout.setHorizontalGroup(
            jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel4))
                .addGap(34, 34, 34)
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jchkFlagPpto)
                    .addGroup(jpDatosLayout.createSequentialGroup()
                        .addComponent(jcbTipoCtaContDH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(jpDatosLayout.createSequentialGroup()
                        .addComponent(jtfCtaCont, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jlCta, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtfDescCtaCont, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpDatosLayout.setVerticalGroup(
            jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jlCta)
                    .addComponent(jtfCtaCont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfDescCtaCont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jcbTipoCtaContDH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jchkFlagPpto))
                .addContainerGap(11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jpOperaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jpDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpOperaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void jtfCtaContActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCtaContActionPerformed
    this.jtfDescCtaCont.requestFocus();
}//GEN-LAST:event_jtfCtaContActionPerformed

private void jtfDescCtaContActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescCtaContActionPerformed
    this.jcbTipoCtaContDH.requestFocus();
}//GEN-LAST:event_jtfDescCtaContActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JComboBox jcbTipoCtaContDH;
    private javax.swing.JCheckBox jchkFlagPpto;
    private javax.swing.JLabel jlCta;
    private javax.swing.JPanel jpDatos;
    private javax.swing.JPanel jpOperaciones;
    private javax.swing.JTextField jtfCtaCont;
    private javax.swing.JTextField jtfDescCtaCont;
    // End of variables declaration//GEN-END:variables
    private Utiles_PanelBotonesMantenimiento upbm;
    private int operacion;
    
    private String idCtaCont = "";
    private String descCtaCont = "";
    private String tipoCtaCont = "";
    private boolean flagPpto = false;
        
    public static int OPERACION_NUEVO = 1;
    public static int OPERACION_MODIFICA = 2;    
}
